<?php include_once dirname(__FILE__).'/common/header.php'; ?>

<?php include_once dirname(__FILE__).'/common/menu.php'; ?>

var attr = <?php echo json_encode($attr) ?>;
var ctrlName = '<?php echo $ctrlName ?>';

attr.template_arr = [];
for(var i=0; i < attr.template_list.length; i++) {
  attr.template_arr.push([attr.template_list[i].template_id ,attr.template_list[i].template_name]);
}

list.statusFrm = function(r,msg,method){
    Ext.Msg.confirm('确认?',msg,function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl +  ctrlName + method,
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}


list.grid = new ZM.GridPanel({
    url: list.baseUrl + 'customer/getCustomerList',
    region: 'center',
    tbar:[{
      text:'同步',
      cls:'btn-show',
      handler:function() {
        list.statusFrm({customer_id:0},'确定需要同步?','/sysnCustomerFromWx');
      }
    }],
    columns:[
        {header:'ID',dataIndex:'customer_id',filter:{},width: 60},
        {header:'头像',dataIndex:'headimgurl',width:50,renderer:function(val) {
          return '<a href="'+val+'" target="_black"><img width="50" src="'+val+'"/></a>';
        }},
        {header:'昵称',dataIndex:'nickname',filter:{}},
        {header:'openid',dataIndex:'openid',filter:{}},
        {header:'性别',dataIndex:'sex',width:60,renderer:function(v) {
          if(v == 1) return '男';
          if(v == 2) return '女';
          return '未知';
        }},
        {header:'城市',dataIndex:'city',width: 60,filter:{}},
        {header:'省份',dataIndex:'province',width: 60,filter:{}},
        {header:'国家',dataIndex:'country',width: 60,toggle:true},
        {header:'关注',dataIndex:'subscribe',width:65,renderer:ZM.status,filter:{
            xtype:'combofield',
            options:[['','全部'],['0','未关注'],['1','已关注']]
        }},
        /*
        {header:'状态',dataIndex:'customer_status',width:65,renderer:ZM.status,filter:{
            xtype:'combofield',
            options:[['','全部'],['0','禁用'],['1','激活']]
        }},
        */
        {header:'红包次数',dataIndex:'customer_hb_times',sort:true,width:60},
        {header:'最后红包时间',dataIndex:'customer_time_last_hb',width:130},
        {header:'关注时间',dataIndex:'customer_time_subscribe',width:130,filter:{xtype:'daterangefield'}},
        {header:'导入时间',dataIndex:'customer_time_create',toggle:true,width:130,filter:{xtype:'daterangefield'}},
        //{header:'最后操作时间',dataIndex:'customer_time_lastmodified',width:130},
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            str += Ext.rd('发红包','fireSend',r,ctrlName + '/sendHongbao');
            //str += Ext.rd('红包记录','fireHistory',r,ctrlName + '/getHistoryList');
            return str;
        }}
    ]
});


list.grid.fireSend = function(r) {
  var r = r.json;
  var win = new ZM.PopUp({
      title:'发送红包',
      defaults:{labelWidth: 120},
      items:{
          xtype:'formpanel',
          url:list.baseUrl+ ctrlName+'/sendHongbao',
          success:function(res) {
              ZM.bo.msg('success',res.detail);
              list.grid.store.reload();
              win.close();
          },
          items:[{
            xtype: 'hidden',
            name: 'customer_id',
            value: r.customer_id
          },{
            xtype: 'hidden',
            name: 'openid',
            value: r.openid
          },{
            xtype: 'hidden',
            name: 'template_id',
            id:'js_template_id',
          },{
              xtype:'combofield',
              fieldLabel:'红包模板',
              name:'template_id',
              options: attr.template_arr,
              allowBlank:false,
              listeners: {
                'select': function(combo,json,index) {
                  var template = attr.template_list[index];
                  Ext.getCmp('js_history_name').setValue(template['template_name']);
                  Ext.getCmp('js_template_id').setValue(template['template_id']);
                  Ext.getCmp('js_history_money').setValue(template['template_money']);
                  Ext.getCmp('js_history_support').setValue(template['template_support']);
                  Ext.getCmp('js_history_wish').setValue(template['template_wish']);
                }
              }
          },{
              fieldLabel:'名称',
              name:'history_name',
              id:'js_history_name',
              allowBlank:false
          },{
              xtype:'numberfield',
              fieldLabel:'金额(元)',
              name:'history_money',
              id:'js_history_money',
              allowBlank:false
          },{
              fieldLabel:'提供方名称',
              name:'history_support',
              id:'js_history_support',
              allowBlank:false
          },{
              fieldLabel:'祝福语',
              name:'history_wish',
              id:'js_history_wish',
              allowBlank:false
          }]
      }
  }).show();
}


/*
list.grid.fireDetail = list.grid.fireHistory = function(r) {
  var r = r.json;
  list.detail.show().ownerCt.doLayout();
  list.history.baseParams = {'customer_id': r.customer_id};
  list.history.load();
}
*/

list.history = new ZM.EditorGridPanel({
  url: list.baseUrl + 'customer/getHistoryList',
  columns:[
    {header:'金额(元)',dataIndex:'history_money'},
    {header:'名称',dataIndex:'history_name',filter:{}},
    {header:'祝福语',dataIndex:'history_wish',id:'aeColumn',filter:{}},
    {header:'提供方名称',dataIndex:'history_support',width:150,filter:{}},
    {header:'状态',dataIndex:'history_status',width:65},
    {header:'返回结果',dataIndex:'history_result',width:150},
    {header:'最后修改时间',dataIndex:'history_time_lastmodified',width:140}
  ]
});

list.detail = new ZM.detailPanel({
  items: list.history
});



<?php include_once dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include_once dirname(__FILE__).'/common/footer.php'; ?>
